//
//  PingLunTableViewCell.m
//  TQY
//
//  Created by 甘世清 on 2024/7/11.
//

#import "PingLunTableViewCell.h"

@implementation PingLunTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self.contentView.backgroundColor = UIColor.whiteColor;
    UIView * bgView = [[UIView alloc]init];
    bgView.layer.cornerRadius = 4;
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 0, 2, 0));
    }];
    
    [bgView addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(40);
        make.left.equalTo(bgView).offset(14);
        make.top.equalTo(bgView).offset(10);
    }];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.top.equalTo(self.headerView);
    }];
    
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.bottom.equalTo(self.headerView.mas_bottom);
    }];
//    [bgView addSubview:self.noloveBtn];
//    [self.noloveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(bgView).offset(-60);
//        make.width.mas_equalTo(40);
//        make.height.mas_equalTo(30);
//        make.centerY.equalTo(self.headerView);
//    }];
//    [bgView addSubview:self.loveBtn];
//    [self.loveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(bgView);
//        make.width.mas_equalTo(60);
//        make.height.mas_equalTo(30);
//        make.centerY.equalTo(self.headerView);
//    }];
    
    [bgView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.headerView.mas_bottom).offset(10);
        make.right.equalTo(bgView.mas_right).offset(-14);
    }];
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = SQColorF1F1F1;
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(1);
    }];
    self.FS_cellBottomView = self.messageLabel;
    WS(weakSelf);
    [self.loveBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_loveButtonClick];
    }];
    [self.noloveBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_noloveButtonClick];
    }];
}


- (void)setModel:(MottoModel *)model{
    _model = model;
    self.messageLabel.text = model.content;
    
    
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"1")];
    
    self.nameLabel.text = model.username;
    self.timeLabel.text = model.createTime;
}
-(void)SQ_loveButtonClick{
    if ([self.loveBtn.text isEqualToString:@"0"]) {
        self.loveBtn.text = @"1";
        _loveBtn.image = SQGetImage(@"dianzan-2");
    } else {
        self.loveBtn.text = @"0";
        _loveBtn.image = SQGetImage(@"dianzan");
    }
    _noloveBtn.image = SQGetImage(@"xinsui");
}
-(void)SQ_noloveButtonClick{
    _loveBtn.image = SQGetImage(@"dianzan");
    self.loveBtn.text = @"0";
    _noloveBtn.image = SQGetImage(@"xinsui 1");
}

-(void)SQ_headerViewButtonClick{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = self.model.uid;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_REGULAR(13);
        _messageLabel.textColor = UIColor.blackColor;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(14);
        _nameLabel.textColor = UIColor.blackColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(10);
        _timeLabel.textColor = SQColor666666;
        _timeLabel.backgroundColor = UIColor.clearColor;
    }
    return _timeLabel;
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_headerViewButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _headerView.layer.cornerRadius = 20;
        _headerView.layer.masksToBounds = YES;
    }
    return _headerView;
}

- (SQCustomButton *)loveBtn{
    if (!_loveBtn) {
        _loveBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(14, 14) midmargin:4];
        _loveBtn.image = SQGetImage(@"dianzan");
        _loveBtn.textColor = SQColor666666;
        _loveBtn.font = FONT_REGULAR(13);
        _loveBtn.text = SQNSLocalString(@"0");
    }
    return _loveBtn;
}
- (SQCustomButton *)noloveBtn{
    if (!_noloveBtn) {
        _noloveBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(14, 14) midmargin:0];
        _noloveBtn.image = SQGetImage(@"xinsui");
    }
    return _noloveBtn;
}
@end
